from dataclasses import dataclass

# from framework.adapter.auth import StringAuth2Instance
from networkx.tests.test_convert_pandas import pd


from config.basic import FieldsMapper


@dataclass
class BaseChartsDTO:
    name: str
    power: str
    posiste: str
    max_hp: int
    attack_value: int
    mind_value: int
    authority: str
    money: int
    manager_point: str
    in_jail: str # ENUM ("TRUE", "FALSE")
    is_die: bool
    now_hp: int
    now_mp: int
    up_hp: int
    up_mp: int
    up_attack: int
    job: int
    yellovalue: int
    reputation: int
    beatful_valu: int
    legion_count: int
    legion_name: str
    is_in_brothel: bool
    is_obscenity: bool
    reincarnation: int
    farmland: str
    ware: str
    mod: str

filename = "./datas/Chars.xlsx"

myChartTable = pd.read_excel(filename)

class BaseCharts:
    def __init__(self, fields):
        self.fields: BaseChartsDTO = fields

    def save(self):
        ChartSave.saveCharacter(self)

    def __repr__(self):
        return str(self.fields)


class ChartSave:
    """
    利用角色的信息进行保存
    """

    @classmethod
    def saveCharacter(cls, chart: BaseCharts) -> None:
        global myChartTable

        chart_name = chart.fields.name
        df: pd.DataFrame = myChartTable
        print(f"[存储层] 有属性被修改, 正在对{chart.fields.name}角色进行保存")

        for key, value in FieldsMapper.items():
            df.loc[df["姓名"] == chart_name, key] = chart.fields.__getattribute__(value)

        df.to_excel("./datas/Chars.xlsx",index=None)
        myChartTable = df
